﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HKEA.CMS.Core.IDAL.Tbl;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.DALFactory;
using HKEA.CMS.Core.Utility;

namespace HKEA.CMS.Core.BLL.Tbl
{
    public class tblCust_BranchBLL
    {
        private  ItblCust_Branch IDAL;
        public tblCust_BranchBLL()
        {
            IDAL = DataAccess.CreateItblCust_Branch();
        }
        /// <summary>
        /// 创建对象
        /// </summary>
        /// <returns></returns>
        public static tblCust_BranchBLL GetInstance()
        {
            return new tblCust_BranchBLL();
        }
        /// <summary>
        /// 插入一条记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int InsertENT(tblCust_Branch ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret= IDAL.InsertENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }

        public tblCust_Branch InsertENTReturnENT(tblCust_Branch ent)
        {
            tblCust_Branch ret = new tblCust_Branch();
            if (ent != null)
            {
                try { ret = IDAL.InsertENTReturnENT(ent); }
                catch (Exception er) { throw er; }
            }
            return ret;
        }

        /// <summary>
        /// 物理删除
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int DeleteENT(tblCust_Branch ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.DeleteENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 修改记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int UpdateENT(tblCust_Branch ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.UpdateENT(ent);
                }
                catch (Exception)
                {

                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<tblCust_Branch> GetListByENT(tblCust_Branch ent,PageParam param, string strPropertyName,string strOrderBy)
        {
            List<tblCust_Branch> list=new List<tblCust_Branch>();
            if (ent != null && param != null)
            {
                try
                {
                    list= IDAL.GetListByENT(ent,param,strPropertyName,strOrderBy);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }
        /// <summary>
        /// 根据条件得到符合条件的结果集，不带分页参数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public List<tblCust_Branch> GetListByENT(tblCust_Branch ent)
        {
            List<tblCust_Branch> list = new List<tblCust_Branch>();
            if (ent != null)
            {
                try
                {
                    list = IDAL.GetListByENT(ent);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return list;
        }

        public tblCust_Branch GetEntity(tblCust_Branch ent)
        {
            return GetListByENT(ent).FirstOrDefault();
        }

        public List<BranchListDetail> GetListDetailByENT(tblCust_Branch ent)
        {
            List<BranchListDetail> list = new List<BranchListDetail>();
            if (ent != null)
            {
                try { list = IDAL.GetListDetailByENT(ent); }
                catch (Exception er) { throw er; }
            }
            return list;
        }
        public List<M_BranchListDetail> GetListByCustUID(List<int> ids, int custUID)
        {
            List<M_BranchListDetail> list = new List<M_BranchListDetail>();
            if (custUID > 0)
            {
                try { list = IDAL.GetListByCustUID(ids,custUID); }
                catch (Exception er) { throw; }
            }
            return list;
        }
        public List<tblCust_Branch> GetListByListID(List<int> list)
        {
            List<tblCust_Branch> retList = new List<tblCust_Branch>();
            if (list.Count > 0)
            {
                try
                {
                    retList = IDAL.GetListByListID(list);
                }
                catch (Exception)
                {
                    throw;
                }
            }
            return retList;
        }

        /// <summary>
        /// 根据条件得到符合条件的记录条数
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public int GetCountByENT(tblCust_Branch ent)
        {
            int ret = 0;
            if (ent != null)
            {
                try
                {
                    ret = IDAL.GetCountByENT(ent);
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }
            return ret;
        }
        /// <summary>
        /// 判断是否已存在符合条件的记录
        /// </summary>
        /// <param name="ent"></param>
        /// <returns></returns>
        public bool IsExist(tblCust_Branch ent)
        {
            bool ret = false;
            if (ent != null)
            {
                if (GetCountByENT(ent) > 0)
                    ret = true;
            }
            return ret;
        }
    }
}
